#include <iostream>

using namespace std;

struct ListNode 
{
	int val;
	ListNode *next;
	ListNode(int x) : val(x), next(NULL) {}
};

class Solution
{
public:
    ListNode *rotateRight(ListNode *head, int k) 
	{
        // Start typing your C/C++ solution below
        // DO NOT write int main() function

		if(!head || k<=0)
			return head;


		ListNode *first = head, *second = head;
		int len = 1;
		while(first->next)
		{
			first = first->next;
			len++;
		}
		first = head;

		if(len == 1)
			return head;
		k %= len;
		if(!k)
			return head;
		
		for(int i=1;i<k;i++)
		{
			if(second)
				second = second->next;
			else
				break;
		}

		if(!second || !(second->next))
			return head;

		ListNode *pre;

		while(second->next)
		{
			pre = first;
			first = first->next;
			second = second->next;
		}

		second->next = head;
		pre->next = NULL;
		return first;        
    }
};

int main()
{
	int n;
	Solution s;
	while(cin>>n)
	{
		if(n==0)
			break;
		int k;
		cin>>k;
		ListNode *head = NULL;
		ListNode* current = NULL;
		for(int i=0;i<n;i++)
		{
			if(!current)
			{
				head = current = new ListNode(0);
			}
			else
			{
				current->next = new ListNode(0);
				current = current->next;
			}
			cin>>current->val;
		}

		current = s.rotateRight(head,k);
		while(current)
		{
			cout<<current->val<<" ";
			current = current->next;
		}		
		cout<<endl;
	}
}
